using NUnit.Framework;
using WWB.DisqusSharp.Model;
using WWB.DisqusSharp.Model.DisqusDTO;
using WWB.DisqusSharp.Model.DisqusService;

namespace WWB.DisqusSharp.Tests.ModelSerialization
{
    [TestFixture]
    [Category("Unit Tests")]
    public class PostsPayloadTests
    {
        private IDisqusServiceResult<ThreadPost[]> resultBase;

        [TestFixtureSetUp]
        public void ArrangeAndAct()
        {
            #region json string
            string json =
                "{\"message\": [{\"status\": \"approved\", \"message\": \"Yo yo, santa, bring me one of dese: http://www.dcr62.net/Web%20Page%20Pics/Front%20Cover%20Pic.JPG \", \"ip_address\": \"66.240.5.72\", \"id\": \"70051891\", \"parent_post\": null, \"imported\": 0, \"forum\": {\"created_at\": \"2010-08-12 13:44:35.983096\", \"shortname\": \"cableintheclassroom\", \"description\": \"\", \"id\": \"438500\", \"name\": \"Cable In the Classroom\"}, \"thread\": {\"category\": \"445069\", \"allow_comments\": true, \"hidden\": false, \"forum\": \"438500\", \"title\": \"http://localhost/cicsite/demos/disqus\", \"url\": \"http://localhost/cicsite/demos/disqus\", \"created_at\": \"2010-08-19T15:38\", \"identifier\": [\"http://localhost/cicsite/demos/disqus\"], \"id\": \"131317088\", \"slug\": \"thread_45\"}, \"author\": {\"username\": \"nctait\", \"email_hash\": \"06332dfabc45fe020a772899e67cd63a\", \"display_name\": \"\", \"has_avatar\": false, \"url\": \"\", \"email\": \"ncta-admin@ncta.com\", \"avatar\": {\"small\": \"http://mediacdn.disqus.com/1071/images/noavatar32.png\", \"large\": \"http://mediacdn.disqus.com/1071/images/noavatar128.png\", \"medium\": \"http://mediacdn.disqus.com/1071/images/noavatar92.png\"}, \"id\": 3904112}, \"created_at\": \"2010-08-19T18:51\", \"is_anonymous\": false, \"points\": 0, \"has_been_moderated\": true}, {\"status\": \"killed\", \"message\": \"bah humbug. Santa must die.\", \"ip_address\": \"66.240.5.72\", \"id\": \"70049838\", \"parent_post\": null, \"imported\": 0, \"forum\": {\"created_at\": \"2010-08-12 13:44:35.983096\", \"shortname\": \"cableintheclassroom\", \"description\": \"\", \"id\": \"438500\", \"name\": \"Cable In the Classroom\"}, \"thread\": {\"category\": \"445069\", \"allow_comments\": true, \"hidden\": false, \"forum\": \"438500\", \"title\": \"http://localhost/cicsite/demos/disqus\", \"url\": \"http://localhost/cicsite/demos/disqus\", \"created_at\": \"2010-08-19T15:38\", \"identifier\": [\"http://localhost/cicsite/demos/disqus\"], \"id\": \"131317088\", \"slug\": \"thread_45\"}, \"author\": {\"username\": \"twitter-14119425\", \"email_hash\": \"d41d8cd98f00b204e9800998ecf8427e\", \"display_name\": \"Wyatt Barnett\", \"has_avatar\": false, \"url\": \"http://twitter.com/wwb_99\", \"email\": \"\", \"avatar\": {\"small\": \"http://mediacdn.disqus.com/1071/images/noavatar32.png\", \"large\": \"http://mediacdn.disqus.com/1071/images/noavatar128.png\", \"medium\": \"http://mediacdn.disqus.com/1071/images/noavatar92.png\"}, \"id\": 3981321}, \"created_at\": \"2010-08-19T18:42\", \"is_anonymous\": false, \"points\": 0, \"has_been_moderated\": true}, {\"status\": \"approved\", \"message\": \"I hate santa claus.\", \"ip_address\": \"66.240.5.72\", \"id\": \"70004695\", \"parent_post\": null, \"imported\": 0, \"forum\": {\"created_at\": \"2010-08-12 13:44:35.983096\", \"shortname\": \"cableintheclassroom\", \"description\": \"\", \"id\": \"438500\", \"name\": \"Cable In the Classroom\"}, \"thread\": {\"category\": \"445069\", \"allow_comments\": true, \"hidden\": false, \"forum\": \"438500\", \"title\": \"http://localhost/cicsite/Preview/Page/1002?key=WvTAxsm84urxr%2btBbusUIcm4Z9u70Y9%2bQs7Kqj3OACo%3d\", \"url\": \"http://localhost/cicsite/Preview/Page/1002?key=WvTAxsm84urxr%2btBbusUIcm4Z9u70Y9%2bQs7Kqj3OACo%3d\", \"created_at\": \"2010-08-19T15:21\", \"identifier\": [\"http://localhost/cicsite/Preview/Page/1002?key=WvTAxsm84urxr%2btBbusUIcm4Z9u70Y9%2bQs7Kqj3OACo%3d\"], \"id\": \"131312042\", \"slug\": \"thread_17\"}, \"author\": {\"username\": \"nctait\", \"email_hash\": \"06332dfabc45fe020a772899e67cd63a\", \"display_name\": \"\", \"has_avatar\": false, \"url\": \"\", \"email\": \"ncta-admin@ncta.com\", \"avatar\": {\"small\": \"http://mediacdn.disqus.com/1071/images/noavatar32.png\", \"large\": \"http://mediacdn.disqus.com/1071/images/noavatar128.png\", \"medium\": \"http://mediacdn.disqus.com/1071/images/noavatar92.png\"}, \"id\": 3904112}, \"created_at\": \"2010-08-19T15:21\", \"is_anonymous\": false, \"points\": 0, \"has_been_moderated\": true}, {\"status\": \"killed\", \"message\": \"blah blah blah\", \"ip_address\": \"66.240.5.72\", \"id\": \"68226765\", \"parent_post\": null, \"imported\": 0, \"forum\": {\"created_at\": \"2010-08-12 13:44:35.983096\", \"shortname\": \"cableintheclassroom\", \"description\": \"\", \"id\": \"438500\", \"name\": \"Cable In the Classroom\"}, \"thread\": {\"category\": \"445069\", \"allow_comments\": true, \"hidden\": false, \"forum\": \"438500\", \"title\": \"http://localhost/cicsite/Preview/Page/1000?key=Vb7pe53ugfQ3bLr8HbQo1VD%2bH3%2fZQewmZ0zfJwLNLWM%3d\", \"url\": \"http://localhost/cicsite/Preview/Page/1000?key=Vb7pe53ugfQ3bLr8HbQo1VD%2bH3%2fZQewmZ0zfJwLNLWM%3d\", \"created_at\": \"2010-08-12T18:16\", \"identifier\": [\"http://localhost/cicsite/Preview/Page/1000?key=Vb7pe53ugfQ3bLr8HbQo1VD%2bH3%2fZQewmZ0zfJwLNLWM%3d#\"], \"id\": \"128985216\", \"slug\": \"thread\"}, \"author\": {\"username\": \"nctait\", \"email_hash\": \"06332dfabc45fe020a772899e67cd63a\", \"display_name\": \"\", \"has_avatar\": false, \"url\": \"\", \"email\": \"ncta-admin@ncta.com\", \"avatar\": {\"small\": \"http://mediacdn.disqus.com/1071/images/noavatar32.png\", \"large\": \"http://mediacdn.disqus.com/1071/images/noavatar128.png\", \"medium\": \"http://mediacdn.disqus.com/1071/images/noavatar92.png\"}, \"id\": 3904112}, \"created_at\": \"2010-08-12T18:16\", \"is_anonymous\": false, \"points\": 0, \"has_been_moderated\": true}], \"code\": \"ok\", \"succeeded\": true}";

            #endregion

            resultBase = new DisqusServiceResultWrapper<ThreadPost[]>(json);
        }

        [Test]
        public void Result_is_not_null()
        {
            Assert.That(resultBase, Is.Not.Null);
        }

        [Test]
        public void Result_has_expected_scalars()
        {
            Assert.That(resultBase.Error, Is.Null);
            Assert.That(resultBase.IsSuccessful);
        }

        [Test]
        public void Result_has_messages_with_correct_count()
        {
            Assert.That(resultBase.Payload, Is.Not.Null);
            Assert.That(resultBase.Payload.Length, Is.EqualTo(4));
        }

        [Test]
        public void Result_message_0_spot_check()
        {
            var fp = resultBase.Payload[0];
            Assert.That(fp.Id, Is.EqualTo("70051891"));
            Assert.That(fp.Message, Is.EqualTo("Yo yo, santa, bring me one of dese: http://www.dcr62.net/Web%20Page%20Pics/Front%20Cover%20Pic.JPG "));
            Assert.That(fp.Thread.Id, Is.EqualTo("131317088"));

        }

        [Test]
        public void Result_message_1_spot_check()
        {
            var fp = resultBase.Payload[1];
            Assert.That(fp.Id, Is.EqualTo("70049838"));
            Assert.That(fp.Forum.Id, Is.EqualTo("438500"));
            Assert.That(fp.Message, Is.EqualTo("bah humbug. Santa must die."));
            Assert.That(fp.IsAnonymous, Is.False);
        }

        [Test]
        public void Result_message_2_spot_check()
        {
            var fp = resultBase.Payload[2];
            Assert.That(fp.Id, Is.EqualTo("70004695"));
            Assert.That(fp.CreatedAt.Day, Is.EqualTo(19));
            Assert.That(fp.CreatedAt.Minute, Is.EqualTo(21));
            Assert.That(fp.Author.EmailHash, Is.EqualTo("06332dfabc45fe020a772899e67cd63a"));
            Assert.That(fp.ParentPostId, Is.Null);
            Assert.That(fp.Thread.Url, Is.EqualTo("http://localhost/cicsite/Preview/Page/1002?key=WvTAxsm84urxr%2btBbusUIcm4Z9u70Y9%2bQs7Kqj3OACo%3d"));
        }

        [Test]
        public void Result_message_3_spot_check()
        {
            var fp = resultBase.Payload[3];
            Assert.That(fp.Id, Is.EqualTo("68226765"));
            Assert.That(fp.Author.Email, Is.EqualTo("ncta-admin@ncta.com"));
            Assert.That(fp.CreatedAt.Hour, Is.EqualTo(18));
            Assert.That(fp.CreatedAt.Minute, Is.EqualTo(16));
            Assert.That(fp.Message, Is.EqualTo("blah blah blah"));
        }
    }
}